package com.summer.order.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.summer.core.controller.EntityQuery;
import com.summer.order.model.Cookbook;
import com.summer.order.model.DayFood;

@Component
public class CookbookList extends EntityQuery<Cookbook>{

	@Resource
	HibernateTemplate ht;
	List<DayFood> dayFoods; 
	
	private Cookbook cookbook;

	
	private String COUNT_HQL = "select count(cookbook) from Cookbook cookbook";
	private String HQL = "select distinct cookbook from Cookbook cookbook";
	public CookbookList() {
		setCountHql(COUNT_HQL);
		setHql(HQL);
	}
	
	
	
	public List<DayFood> getDayFoods() {
		if(cookbook == null) {
			return null;
		}
		dayFoods = ht.find("from DayFood df "
				+ "where df.cookbook.id =?",cookbook.getId());
		return dayFoods;
	}
	public void setDayFoods(List<DayFood> dayFoods) {
		this.dayFoods = dayFoods;
	}
	
	
	
	public Cookbook getCookbook() {
		return cookbook;
	}

	public void setCookbook(Cookbook cookbook) {
		this.cookbook = cookbook;
	}

	
	
	
	
	
	
}
